package ibmetp.mis.controller.resource;

import ibmetp.mis.common.Constants;
import ibmetp.mis.service.ResourceService;
import ibmetp.mis.service.UserService;
import ibmetp.mis.serviceImpl.ResourceServiceImpl;
import ibmetp.mis.serviceImpl.UserServiceImpl;
import ibmetp.mis.vo.Dept;
import ibmetp.mis.vo.Page;
import ibmetp.mis.vo.Resource;
import ibmetp.mis.vo.User;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class roleResPageServlet
 */
public class roleResPageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public roleResPageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 request.setCharacterEncoding(Constants.ENCODING_UTF8);
		 System.out.println("call RoleResPageServlet...");
			
			//当前页号
			int pageNo=request.getParameter("page")!=null?Integer.parseInt(request.getParameter("page")):1;
			System.out.println("pageNo:"+pageNo);
			
			//页面大小
			int pageSize=request.getParameter("rows")!=null?Integer.parseInt(request.getParameter("rows")):2;
			System.out.println("pageSize:"+pageSize);
			//角色Id
			Long roleId=Long.valueOf(request.getParameter("roleId"));
			//查询条件User
			Resource res=new Resource();
			res.setResourceName(request.getParameter("resourceName"));
			
			//查询数据
			ResourceServiceImpl rs=new ResourceServiceImpl();
		
			Page p=rs.getRoleResPage(roleId, pageNo, pageSize, res);	   
			
			//输出JSON数据
			JSONObject o=new JSONObject();
			o.put("rows",p.getList());
			o.put("total",p.getTotal());
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().write(o.toString());
	}

}
